import {BasicColumn, FormSchema} from '@apps/antd-admin/src/components/table';
import {Api, getCompanyInfo} from './api';
import {RenderType} from '@pkg/setting';
import {useUserStore} from "@apps/antd-admin/src/store/user";
import {rules} from '@pkg/utils';
import {render} from "@apps/antd-admin/src/hooks/render/renderUtils";

export const columns: BasicColumn[] = [
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 80,
    renderType: RenderType.AVATAR,
  },
  {
    title: '登录账号',
    dataIndex: 'accountName',
    width: 100,
  },
  {
    title: '企业',
    dataIndex: 'companyName',
    width: 100,
  },
  {
    title: '姓名',
    dataIndex: 'nickName',
    width: 150,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    renderApi: Api.setUserStatus,
    rowKey: 'userId',
    customRender: render.renderSwitch
  },
  {
    title: '评估次数',
    dataIndex: 'busNum',
    width: 60
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'accountName',
    label: '登录账号',
    component: 'Input',
    colProps: {span: 3},
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: {span: 3},
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '代理商',
    field: 'companyId',
    component: 'ApiSelect',
    componentProps: ({formModel, formActionType}) => {
      return {
        api: Api.companyList,
        labelField: 'companyName',
        valueField: 'companyId',
        immediate: true,
        onChange(companyId) {
          getCompanyInfo({
            companyId: companyId
          }).then((data) => {
            formModel.busTotalNum = data.busTotalNum;
          })
        }
      }
    },
    ifShow: () => {
      return useUserStore().isSuperAdmin
    },
  },
  {
    field: 'nickName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'accountName',
    label: '登录账户',
    component: 'Input',
    required: true,
    dynamicDisabled: ({values}) => {
      return values.userId != null
    },
  },
  {
    field: 'password',
    label: '登录密码',
    component: 'InputPassword',
    rules: rules.required(8, 20),
    ifShow: ({values}) => {
      return values.userId == null
    },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    required: false,
  },
  {
    field: 'busTotalNum',
    label: '手机号',
    component: 'Input',
    required: false,
    ifShow: () => {
      return false
    }
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
  },
];

export const changeBusNumFormSchema: FormSchema[] = [
  {
    field: 'busNum',
    label: '评估次数',
    component: 'InputNumber',
  }
];

export const importFormSchema: FormSchema[] = [];
